<?php

class OutilsController extends Zend_Controller_Action
{
	private $base_url;
    public function init()
    {
       $this->base_url = $this->getRequest()->getBaseUrl();
    }

    public function indexAction()
    {
        // action body

    }
    
    public function societeAction(){

		$tva = new Application_Model_TauxTvaMapper();
        $listOptions = $tva->fetchAll();
		$formulaire = new Application_Form_Societe(array("descOption" => $listOptions), $this->base_url);
		
		if ($this->getRequest()->isPost()) {
            if ($formulaire->isValid($this->_getAllParams())) {
				
                $societe = new Application_Model_Societe($formulaire->getValues());

                $mapper  = new Application_Model_SocieteMapper();
                $mapper->save($societe);
                $this->_redirect('/outils/index/');
            }
        }

//		$tableSociete = new Application_Model_DbTable_Societe();
//		$societe = $tableSociete->find(1);
//
//		$formulaire = new Application_Form_Societe(array("descOption" => $listOptions), $this->base_url);
//
//		if($this->getRequest()->isPost()){
//			if($formulaire->isValid($this->_getAllParams())){
//                $data = $formulaire->getValues();
//				var_dump($this->_getAllParams());
//				//if($formulaire->getValue('id_societe') != ""){
//					// update
//					$ts = new Application_Model_SocieteMapper();
//					$s = new Application_Model_Societe($data);
//					$ts->save($s);
//					//$societe = $tableSociete->find($data['id_societe'])->current();
//					//
//					//$societe->setFromArray($data)->save();
//
//					$this->_redirect('/outils/index/');
//				//}else{
//					
//				//}
//			}
//		}else{
//			if(!is_null($societe->current())){
//				$formulaire->populate($societe->current()->toArray());
//			}
//		}
		
		$this->view->form_societe = $formulaire;

    }
}